import { createApp } from 'vue';
import axios from 'axios';
import ViewUIPlus from 'view-ui-plus';
import App from './App.vue';
import router from './router/index';
// import store from './store';
import 'view-ui-plus/dist/styles/viewuiplus.css';

const app = createApp(App);

app.provide('$axios', axios);

app.use(ViewUIPlus).use(router).mount('#app');

router.beforeEach(function (to, from, next) {
  if (to.meta.needLogin) {
    //判断当前是否登录
    let username = localStorage.getItem('username');
    try {
      username = JSON.parse(username);
    } catch (error) {
      username = username;
    }
    if (username) {
      next();
    } else {
      next({ name: 'noLogin' });
    }
  } else {
    //表示不需要登录
    next();
  }
});
